package logic

import (
	"context"
	"rental/rentalrpc/rentalrpc"

	"rental/api/internal/svc"
	"rental/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProdcutListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProdcutListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProdcutListLogic {
	return &ProdcutListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProdcutListLogic) ProdcutList(req *types.ProdcutListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.RentalRpc.ProductList(l.ctx, &rentalrpc.ProductListRequest{})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "商品列表展示成功",
			Code:    200,
			Data:    list,
		}, nil
	}
}
